/*
 * Author : Niharika Soni
 * */
package com.NewsFeedClasses;

import java.util.ArrayList;
import java.util.Iterator;

import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.exception.FacebookGraphException;
import com.restfb.types.Post;

// test class NewsFeedReader to test NewsFeedPosts class
public class NewsFeedReader {

	/**
	 * @param args
	 */
	private static FacebookClient facebookClient;
	public NewsFeedReader(String accessToken)
	{
			facebookClient = new DefaultFacebookClient(accessToken);
	}
	
	public static void main(String[] args) {
		
		    NewsFeedReader newsFeedReader = new NewsFeedReader(getToken());
			Connection<Post> newsFeedConnection = null;
			try
			{
				newsFeedConnection = facebookClient.fetchConnection("me/home", Post.class);
			}
			catch(FacebookGraphException e)
			{
				System.out.println("Facebook GRAPH API error: "+ e.getErrorMessage());
			}
			catch(Exception e)
			{
				System.out.println("error"+ e.getMessage());
			}
			
		    NewsFeedPosts newsFeedPosts = new NewsFeedPosts(facebookClient);
		    ArrayList<NewsFeed> feeds =  newsFeedPosts.fetchNewsFeedPosts();
		    Iterator<NewsFeed> itr = feeds.iterator();
		    while(itr.hasNext())
		    {
		    	NewsFeed feedObj = itr.next();
		    	System.out.println("NewsFeed : ");
		    	System.out.println("Message : "+feedObj.getNewsFeedMessage());
		    	System.out.println("Like_Count : "+feedObj.getNewFeedLikeCount());
		    	System.out.println("#####################################");
		    }
	}
	// method to get the access token. and need to replace the token with token in your session.
	private static String getToken()
	{
		String access_token = "2POoGw__.3600.129930245972783jeaOpty2rTqVOs2w"; 
		return access_token;
	}
	
}
